package com.ruoyi.web.wrapper;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.account.enums.ActionTypeEnum;
import com.ruoyi.common.wrapper.BaseControllerWrapper;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AccountOwnerHisWrapper extends BaseControllerWrapper {

    public AccountOwnerHisWrapper(Map<String, Object> single) {
        super(single);
    }

    public AccountOwnerHisWrapper(List<Map<String, Object>> multi) {
        super(multi);

        if (multi != null && !multi.isEmpty()) {
            BigDecimal totalChangeAmount = BigDecimal.ZERO;
            BigDecimal payAmount = BigDecimal.ZERO;
            BigDecimal costAmount = BigDecimal.ZERO;
            for (Map<String, Object> map : multi) {

                totalChangeAmount = totalChangeAmount.add(new BigDecimal(map.get("totalChangeAmount").toString()));
                payAmount = payAmount.add(new BigDecimal(map.get("payAmount").toString()));
            }

            Map<String, Object> totalChangeAmountMap = new HashMap<>();
            totalChangeAmountMap.put("totalChangeAmount", totalChangeAmount);
            totalChangeAmountMap.put("payAmount", payAmount);

            multi.add(0, totalChangeAmountMap);
        }
    }


    @Override
    public void wrapTheMap(Map<String, Object> map) {
        try {

            String actionType = (String) map.get("actionType");
            if (StrUtil.isNotEmpty(actionType)){
                map.put("actionTypeStr", ActionTypeEnum.getNameByValue(actionType));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
